package com.sdry.product.sorting.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdry.common.BaseController;
import com.sdry.common.TableDataInfo;
import com.sdry.product.sorting.entity.SortFrame;
import com.sdry.product.sorting.entity.SortOutOf;
import com.sdry.product.sorting.service.SortingOutOfService;
import com.sdry.system.entity.SysUser;
import com.sdry.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: info_sdry
 * @description: 分拣区出库，可以看做其他流程的（部分）入库
 * @author: cb
 * @create: 2020-02-28 18:05
 **/
@Controller
@RequestMapping(value = "sortingOutOf")
public class SortingOutOfController extends BaseController {

    @Autowired
    private SortingOutOfService sortingOutOfService;

    @Autowired
    private UserService userService;

    /**
     * 出库展示部分
     * @return
     */
    @RequestMapping(value = "showSortingOutOf")
    public String showSortingOutOf() {

        return "/product/sorting/outOf";
    }

    /**
     * 分页查询出库
     * @param sortOutOf
     * @return
     */
    @RequestMapping(value = "querySortOutOfPage")
    @ResponseBody
    public TableDataInfo querySortOutOfPage(SortOutOf sortOutOf) {
        Page<SortOutOf> page = new Page<>(sortOutOf.getPage(),sortOutOf.getLimit());
        IPage<SortOutOf> sortOutOfIPage = sortingOutOfService.page(page);
        List<SortOutOf> records = sortOutOfIPage.getRecords();
        for (SortOutOf record : records) {
            SysUser sysUser = userService.getById(record.getReceiveBy());
            record.setRealName(sysUser.getRealName());
        }
        return getDataTable(records,sortOutOfIPage.getTotal());
    }
}
